﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RPGProject.IOBuffers
{
    /// <summary>
    /// A utility class the reads from the console.
    /// </summary>
    class InputBuffer
    {
        /// <summary>
        /// Reads a word from the Console.
        /// </summary>
        /// <returns></returns>
        public static String ReadWord()
        {
            String ret = "";
            char c;
            do
            {
                c = Console.ReadKey().KeyChar;
                ret += c;
            } while (!char.IsWhiteSpace(c));
            return ret;
        }
        /// <summary>
        /// Reads a line from the console.
        /// </summary>
        /// <returns></returns>
        public static String ReadLine()
        {
            String ret = "";
            char c;
            do
            {
                c = Console.ReadKey().KeyChar;
                ret += c;
            } while (!(c == '\r' || c == '\n' || c == (char)13));
            return ret;
        }
        /// <summary>
        /// Returns a ConsoleKeyInfo.
        /// </summary>
        /// <param name="display">Whether to display the character read.</param>
        /// <returns></returns>
        public static ConsoleKeyInfo ReadKey(bool hide = false)
        {
            return Console.ReadKey(hide);
        }

        /// <summary>
        /// Reads a key, and then properly formats to upper and lower case.  Detects arrow keys and numpad.
        /// </summary>
        /// <returns></returns>
        public static string ReadFormattedKey()
        {
            ConsoleKeyInfo cki = InputBuffer.ReadKey();
            String ret = "";
            if ((int)(cki.Modifiers & ConsoleModifiers.Shift) == 0)
            {
                ret = cki.Key.ToString().ToLower();
            }
            else
            {
                ret = cki.Key.ToString().ToUpper();
            }
            return ret;
        }
    }
}
